import Vue from "vue";
import VueRouter from "vue-router";

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
// 页面
import Login from '@/pages/login/Login.vue'
import Home from '@/pages/home/Home.vue'
import Index from '@/pages/Index/index.vue'
// 商品列表与详情
import GoodsList from '@/pages/goodsList/GoodsList.vue'
import GoodsDetail from '@/pages/goodsDetail/GoodsDetail.vue'
// 商品分类列表与详情
import GoodsTypeList from '@/pages/goodsTypeList/GoodsTypeList.vue'
import GoodsTypeAdd from '@/pages/goodsTypeAdd/GoodsTypeAdd.vue'
// 普通订单列表与详情
import OrderList from '@/pages/orderList/OrderList.vue'
import OrderDetail from '@/pages/orderDetail/OrderDetail.vue'
// 普通用户退单列表与详情
import ReturnList from '@/pages/returnList/ReturnList.vue'
import ReturnDetail from '@/pages/returnDetail/ReturnDetail.vue'
//普通用户列表
import UserList from '@/pages/userList/UserList.vue'
import UserDetail from '@/pages/userDetail/UserDetail.vue'
//加盟商列表与详情
import MerchantList from '@/pages/merchantList/MerchantList.vue'
import MerchantDetail from '@/pages/merchantDetail/MerchantDetail.vue'
// 加盟商采购订单列表与详情
import MerchantOrderList from '@/pages/merchantOrderList/MerchantOrderList.vue'
import MerchantOrderDetail from '@/pages/merchantOrderDetail/MerchantOrderDetail.vue'
// 加盟商采购退单列表与详情
import MerchantReturnList from '@/pages/merchantReturnList/MerchantReturnList.vue'
import MerchantReturnDetail from '@/pages/merchantReturnDetail/MerchantReturnDetail.vue'
//加盟商提现审核列表与详情
import MerchantWithdrawList from '@/pages/merchantWithdrawList/MerchantWithdrawList.vue'
import MerchantWithdrawDetail from '@/pages/merchantWithdrawDetail/MerchantWithdrawDetail.vue'
import SellTotal from '@/pages/sellTotal/SellTotal'
//品牌商管理
import BrandDealerList from '@/pages/brandDealerList/BrandDealerList.vue'
import BrandDealerDetail from '@/pages/brandDealerDetail/BrandDealerDetail.vue'
import BrandDealerGoodsList from '@/pages/brandDealerGoodsList/BrandDealerGoodsList.vue'
import BrandDealerGoodsDetail from '@/pages/brandDealerGoodsDetail/BrandDealerGoodsDetail.vue'
//操作日志
import Log from '@/pages/admin/Log/index.vue'
//管理员管理
import User from '@/pages/admin/User/index.vue'
import AdminUserDetail from '@/pages/admin/User/detail.vue'
//没有权限
import Authority from '@/pages/Authority/index.vue'
Vue.use(VueRouter)

const routes=[
    {
		path: '/login',
		name: 'Login',
		component: Login,
		meta: {
			Authority: []
		}
    },
    {
		path: '/',
		component: Home,
		meta: {
			Authority: [1]
		},
      	children: [
			{
				path:'/',
				name:'home',
				component:Index,
				meta:{
					Authority:[]
				}
			},
			{
				path: '/goodsList',
				name: 'GoodsList',
				component: GoodsList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/goodsList/goodsDetail/:id',
				name: 'GoodsDetail',
				component: GoodsDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/goodsTypeList',
				name: 'GoodsTypeList',
				component: GoodsTypeList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/goodsTypeList/goodsTypeAdd/:id',
				name: 'GoodsTypeAdd',
				component: GoodsTypeAdd,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/orderList',
				name: 'OrderList',
				component: OrderList,
				meta: {
					Authority: [1,2]
				}
			},
			{
				path: '/orderList/orderDetail/:id',
				name: 'OrderDetail',
				component: OrderDetail,
				meta: {
					Authority: [1,2]
				}
			},
			{
				path: '/returnList',
				name: 'ReturnList',
				component: ReturnList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/returnList/returnDetail/:order/:id',
				name: 'ReturnDetail',
				component: ReturnDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/userList',
				name: 'UserList',
				component: UserList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/userList/userDetail/:id',
				name: 'UserDetail',
				component: UserDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantList',
				name: 'MerchantList',
				component: MerchantList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantList/merchantDetail/:id',
				name: 'MerchantDetail',
				component: MerchantDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantWithdrawList',
				name: 'MerchantWithdrawList',
				component: MerchantWithdrawList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantWithdrawList/merchantWithdrawDetail/:id',
				name: 'MerchantWithdrawDetail',
				component: MerchantWithdrawDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantOrderList',
				name: 'MerchantOrderList',
				component: MerchantOrderList,
				meta: {
					Authority: [1,2]
				}
			},
			{
				path: '/merchantOrderList/merchantOrderDetail/:id',
				name: 'MerchantOrderDetail',
				component: MerchantOrderDetail,
				meta: {
					Authority: [1,2]
				}
			},
			{
				path: '/merchantReturnList',
				name: 'MerchantReturnList',
				component: MerchantReturnList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/merchantReturnList/merchantReturnDetail/:order/:id',
				name: 'MerchantReturnDetail',
				component: MerchantReturnDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/sellTotal',
				name: 'SellTotal',
				component: SellTotal,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/brandDealerList',
				name: 'BrandDealerList',
				component: BrandDealerList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/brandDealerList/brandDealerDetail/:id',
				name: 'BrandDealerDetail',
				component: BrandDealerDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/brandDealerGoodsList',
				name: 'BrandDealerGoodsList',
				component: BrandDealerGoodsList,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/brandDealerGoodsList/brandDealerGoodsDetail',
				name: 'BrandDealerGoodsDetail',
				component: BrandDealerGoodsDetail,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/admin/log',
				name: 'Log',
				component: Log,
				meta: {
					Authority: [1]
				}
			},
			{
				path: '/admin/user',
				name: 'User',
				component: User,
				meta: {
					Authority: [1]
				}
			},{
				path: '/admin/user/detail/:id',
				name: 'AdminUserDetail',
				component: AdminUserDetail,
				meta: {
					Authority: [1]
				}
			},{
				path: '/403',
				name: '403',
				component: Authority,
				meta: {
					Authority: []
				}
			}
      	]
    }
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    // }
];
  
const router = new VueRouter({
	routes
});

router.beforeEach((to, from, next) => {
	let Authority = Number(localStorage.getItem('Authority'))
	let item = to.meta.Authority.indexOf(Authority)
	if (to.meta.Authority.length>0) {
		if (item != -1) {
			next()
		}else{
			next('/403')
		}
	}else{
		next()
	}
	console.log(item)
	
})
  
export default router;

